package Operation;

import Book.Book;
import Book.BookList;

import java.util.Scanner;

public class AddOperation implements Ioperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("新增图书");
        System.out.println("输入书名：");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        System.out.println("输入作者：");
        String author = scanner.nextLine();
        System.out.println("输入价格：");
        int price = scanner.nextInt();
        scanner.nextLine();
        System.out.println("输入种类：");
        String type = scanner.nextLine();
        Book book = new Book(name,author,price,type);
        int size = bookList.getUsedSize();
        for (int i = 0; i < size; i++) {
            Book CompareBook = bookList.getBooks(i);
            if(CompareBook.getName().equals(book)==true) {
                System.out.println("已存在此书："+book.getName());
                return;
            }
        }
        bookList.setBooks(size,book);
        bookList.setUsedSize(size+1);
    }
}
